package com.cyq.day22.PaintFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class PaintFrame extends JFrame {
    int x,y;
    JLabel label;

    public PaintFrame()  {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(200,100,500,500);
        label=new JLabel();

//        this.addMouseListener(new MouseAdapter() {
//            @Override
//            public void mouseClicked(MouseEvent e) {
//                x=e.getX();
//                y=e.getY();
//                repaint();
//            }
//        });
        this.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                super.mousePressed(e);
                x=e.getX();
                y=e.getY();
                repaint();
            }
        });

        label.setText(x+y+"");
        this.add(BorderLayout.SOUTH,label);
    }

    @Override
    public void paint(Graphics g) {
        g.fillOval(x-15,y-15,30,30);
    }
}
